﻿using SrBBSPro.Entities;
using SrBBSPro.Services;
using SrBBSPro.Models;
using System.Web.Mvc;
using System;
using SrBBSPro.BaseClasses;

namespace SrBBSPro.Controllers
{
    public class CountController : BaseController
    {
        public ActionResult Index()
            => View();

        public ActionResult CountList()
        {
            var li = new CountService().GetCountList(Request["name"], Convert.ToInt32(Request["page"]), out int count);
            return JsonResultForLay<HolidayCount, long>(li, count, false);
        }

        public ActionResult NoteList()
        {
            var li = new NoteService().GetNoteList(Convert.ToInt64(Request["hid"]), Request["staffName"]
                , Request["Depart"], out int count, Convert.ToInt32(Request["page"]));
            return JsonResultForLay<HolidayNote, long>(li, count, false);
        }

        public ActionResult Add()
            => View();

        [HttpPost]
        public ActionResult Add(HolidayCountModel model)
        {          
            var response = new CountService().InsertOrUpdate(model);
            return JsonResultForFly(response.IsSuccess ? 0 : 1, response.Message, "/count/");
        }

        public ActionResult AllList()
            => View(new CountService().GetSingleEntity(EntId));

        public ActionResult Detail()
            => View(new NoteService().GetHolidayById(EntId,string.IsNullOrEmpty(EntNo)?CurrentUserId:EntNo));

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Save(HolidayNoteModel model)
        {
            if (model == null)
                return JsonResultForFly(1, "请勿传递非法参数，请刷新重试！");
            if (model.StartDate == null || model.EndDate == null)
                return JsonResultForFly(1, "请输入日期！");
            model.No = CurrentUserId;
            var response = new NoteService().InsertOrUpdate(model);
            return JsonResultForFly(response.IsSuccess ? 0 : 1, response.Message, "/count/");
        }

        [HttpPost]
        public ActionResult DelCount()
        {
            var response = new CountService().DelCount(Convert.ToInt32(Request["hid"]));
            return JsonResultForFly(response.IsSuccess ? 0 : 1, response.Message);
        }
    }
}